package enhanced.neural.network.controller;

import enhanced.neural.network.dto.CommonResponse;
import enhanced.neural.network.dto.UserInfo;
import enhanced.neural.network.service.UserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/data")
@RestController
public class DataController {

    private final UserService userService;

    public DataController(UserService userService) {
        this.userService = userService;
    }

    @RequestMapping("/query")
    @ResponseBody
    public CommonResponse<List<UserInfo>> testData() {
        List<UserInfo> userInfos = userService.queryUserList();

        return CommonResponse.success(userInfos);
    }

    /**
     * 插入
     * @param list
     * @return
     */
    @RequestMapping("/insert")
    @ResponseBody
    public CommonResponse<Object> insert(@RequestBody List<UserInfo> list) {
        userService.insert(list);
        UserInfo userInfo = new UserInfo();
        return CommonResponse.success();
    }
}
